<template>
  <a-card :bordered="false">
    <div>
      <div style="margin-bottom:24px"></div>
      <a-table
        ref="table"
        size="small"
        :pagination="false"
        :row-key="(r,index)=>index"
        :columns="columns"
        :data-source="list"
        :loading="loading"
      >
        <span slot="create_time" slot-scope="text,record,index">
          <div v-if="index==0">
            <a-range-picker class="input_noborder" @change="onChange" />
          </div>
          <div v-else>{{ text | datatrans }}</div>
        </span>
        <span slot="table_name" slot-scope="text,record,index">
          <div v-if="index==0">
            <a-select style="width:150px" v-model="queryParam.user_operate_table_id">
              <a-select-option
                v-for="(item,uindex) in operatetable"
                :value="item.id"
                :key="uindex"
              >{{ item.name }}</a-select-option>
            </a-select>
          </div>
          <div v-else>{{ text }}</div>
        </span>
        <span slot="data_id" slot-scope="text,record,index">
          <div v-if="index==0">
            <a-input
              class="input_noborder"
              type="text"
              v-model="queryParam.data_id"
              @pressEnter="gets"
            />
          </div>
          <div v-else>{{ text }}</div>
        </span>
        <span slot="operate_name" slot-scope="text,record,index">
          <div v-if="index==0">
            <a-select style="width:100px" v-model="queryParam.user_operate_id">
              <a-select-option
                v-for="(item,uindex) in operate"
                :value="item.id"
                :key="uindex"
              >{{ item.name }}</a-select-option>
            </a-select>
          </div>
          <div v-else>{{ text }}</div>
        </span>
        <span slot="username" slot-scope="text,record,index">
          <div v-if="index==0">
            <a-select style="width:150px" v-model="queryParam.user_id">
              <a-select-option
                v-for="(item,indexu) in user"
                :value="item.id"
                :key="indexu"
              >{{ item.username }}</a-select-option>
            </a-select>
          </div>
          <div v-else>{{ text }}</div>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="remarkHandle(record.remark)">详情</a>
          </template>
        </span>
        <template slot="footer">
          <div style="overflow:hidden">
            <a-pagination
              v-model="pagination.pageNo"
              hide-on-single-page
              :page-size="pagination.pageSize"
              :total="pagination.totalCount"
              style="float: right;"
              @change="pagechange"
              size="small"
              show-quick-jumper
            ></a-pagination>
          </div>
        </template>
      </a-table>
    </div>
    <a-modal v-model="visible" title="备注" width="800px">
      <div style="white-space: pre-line;" v-html="remark"></div>
    </a-modal>
  </a-card>
</template>

<script>
import moment from 'moment'
const columns = [
  {
    title: '数据种类',
    dataIndex: 'table_name',
    scopedSlots: {
      customRender: 'table_name'
    }
  },
  {
    title: '数据主键',
    dataIndex: 'data_id',
    scopedSlots: {
      customRender: 'data_id'
    }
  },
  {
    title: '操作方式',
    dataIndex: 'operate_name',
    scopedSlots: {
      customRender: 'operate_name'
    }
  },
  {
    title: '操作用户',
    dataIndex: 'USER_NAME',
    scopedSlots: {
      customRender: 'USER_NAME'
    }
  },
  {
    title: '时间',
    dataIndex: 'create_time',
    scopedSlots: {
      customRender: 'create_time'
    },
    width: '270px'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '60px',
    fixed: 'right',
    scopedSlots: {
      customRender: 'action'
    }
  }
]
export default {
  components: {},
  data() {
    return {
      columns,
      queryParam: {},
      visible: false,
      remark: '',
      list: [],
      pagination: { total: 0, pageSize: 20, pageNo: 1 },
      loading: true,
      operate: [],
      operatetable: [],
      user: []
    }
  },
  created() {
    this.getselect()
  },
  activated() {
    this.gets()
  },
  watch: {
    'queryParam.user_operate_id'() {
      this.gets()
    },
    'queryParam.user_id'() {
      this.gets()
    },
    'queryParam.user_operate_table_id'() {
      this.gets()
    }
  },
  methods: {
    gets() {
      this.loading = true
      this.$get('/api/user/user_operate_record_gets', Object.assign(this.queryParam, this.pagination)).then(res => {
        this.list = res.data ? [this.queryParam].concat(res.data) : [this.queryParam]
        this.pagination.totalCount = res.totalCount
        this.loading = false
      })
    },
    getselect() {
      this.$get('/api/user/user_operate_gets').then(res => {
        this.operate = res.data || []
      })
      this.$get('/api/user/user_operate_table_gets').then(res => {
        this.operatetable = res.data || []
      })
      this.$get('/api/user/user_gets', {
        pageNo: -1
      }).then(res => {
        this.user = res.data || []
      })
    },
    remarkHandle(r) {
      this.remark = r
      this.visible = true
    },
    pagechange(a, b) {
      this.pagination.pageNo = a
      this.gets()
    },
    onChange(a, dateString) {
      this.queryParam.stime = dateString[0]
      this.queryParam.etime = dateString[1]
      this.gets()
    }
  }
}
</script>
<style>
</style>